// pages/bindPhone/bindPhone.js
var app = getApp()
Page({
  data: {},
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that=this;
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        console.log(res)
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
  , getBindPhone: function (e) {
     console.log(e);
    if (e.detail.value != "") {
      this.setData({
        getBindPhone: e.detail.value
      })
    }
  },
  sendBindPhone: function () {
    var reg = /^1[34578]\d{9}$/;
    if (reg.test(this.data.getBindPhone)) {
      wx.request({

        url: app.globalData.allUrl + "/YMGW/userAction/updateUserPhone",
        // header: { 'content-type': 'application/x-www-form-urlencoded' },
        data: {
          phone: this.data.getBindPhone,
          id: wx.getStorageSync('userid')
        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function (res) {
          if (res.data == true) {
            wx.showToast({
                title: "提交手机号成功",
                icon: "success",
              });
            setTimeout(function () {    
              wx.navigateBack({})
            }, 2000)
          }
        }
      })
    } else {
      wx.showToast({
        title: "请输入正确的手机号",
        icon: "loading",
      })
    }

  }
})